package com.yijiaw.domain;

import java.io.Serializable;

import java.lang.StringBuilder;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import javax.xml.bind.annotation.*;

import javax.persistence.*;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllParts", query = "select myPart from Part myPart"),
		@NamedQuery(name = "findPartById", query = "select myPart from Part myPart where myPart.id = ?1"),
		@NamedQuery(name = "findPartByImage", query = "select myPart from Part myPart where myPart.image = ?1"),
		@NamedQuery(name = "findPartByImageContaining", query = "select myPart from Part myPart where myPart.image like ?1"),
		@NamedQuery(name = "findPartByName", query = "select myPart from Part myPart where myPart.name = ?1"),
		@NamedQuery(name = "findPartByNameContaining", query = "select myPart from Part myPart where myPart.name like ?1"),
		@NamedQuery(name = "findPartByPrimaryKey", query = "select myPart from Part myPart where myPart.id = ?1"),
		@NamedQuery(name = "findPartByRemark", query = "select myPart from Part myPart where myPart.remark = ?1") })
@Table(catalog = "yijiaw", name = "part")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "temp/com/yijiaw/domain", name = "Part")
public class Part implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "name", length = 50)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String name;
	/**
	 */

	@Column(name = "remark", columnDefinition = "TEXT")
	@Basic(fetch = FetchType.EAGER)
	@Lob
	@XmlElement
	String remark;
	/**
	 */

	@Column(name = "image", length = 50)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String image;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "type_id", referencedColumnName = "id") })
	@XmlTransient
	Parttype producttype;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 */
	public String getName() {
		return this.name;
	}

	/**
	 */
	public void setRemark(String remark) {
		this.remark = remark;
	}

	/**
	 */
	public String getRemark() {
		return this.remark;
	}

	/**
	 */
	public void setImage(String image) {
		this.image = image;
	}

	/**
	 */
	public String getImage() {
		return this.image;
	}

	/**
	 */
	public void setProducttype(Parttype parttype) {
		this.producttype = parttype;
	}

	/**
	 */
	public Parttype getProducttype() {
		return producttype;
	}

	/**
	 */
	public Part() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Part that) {
		setId(that.getId());
		setName(that.getName());
		setRemark(that.getRemark());
		setImage(that.getImage());
		setProducttype(that.getProducttype());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("name=[").append(name).append("] ");
		buffer.append("remark=[").append(remark).append("] ");
		buffer.append("image=[").append(image).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Part))
			return false;
		Part equalCheck = (Part) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
